package com.byedu.course.controller;

import com.byedu.course.LibraryService;
import com.byedu.domain.course.vo.*;
import com.byedu.domain.course.LibraryDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author chenxigui
 * @description 专题
 * @date 2017-04-25
 */

@Controller
@RequestMapping("/library")
public class LibraryController {
    @Autowired
    private LibraryService libraryService;

    /**
     * @param courseId
     * @return
     * @description 获取专题课程列表
     * @author jason
     * @date 2017-04-26
     */
    @ResponseBody
    @RequestMapping(value = "/list/{courseId}", method = {RequestMethod.GET})
    public List<LibraryVO> getLibrariesByCourseId(@PathVariable Integer courseId) {
        return libraryService.listLibrariesByCourseId(courseId);

    }

    @ResponseBody
    @RequestMapping(value = "/list/{courseId}/{userId}", method = {RequestMethod.GET})
    public List<LibraryVO> getLibrariesByCourseIdUserId(@PathVariable Integer courseId, @PathVariable String userId) {
        return libraryService.listLibrariesByCourseId(courseId);

    }

    @ResponseBody
    @RequestMapping(value = "/add", method = {RequestMethod.GET})
    public void add() {
        LibraryDO libraryVO = new LibraryDO();
        libraryVO.setName("888");
        libraryVO.setCourseId(7);
        libraryVO.setLibraryType("tip");
        libraryVO.setTrialNum(10);

        libraryService.saveLibrary(libraryVO);


    }


}
